package top.ywlog.service.impl;

import org.springframework.stereotype.Service;
import top.ywlog.mapper.CustomersDao;
import top.ywlog.model.Customers;
import top.ywlog.service.CustomersService;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Customers)表服务实现类
 *
 * @author makejava
 * @since 2021-01-30 11:43:27
 */
@Service("customersService")
public class CustomersServiceImpl implements CustomersService
{
    @Resource
    private CustomersDao customersDao;

    /**
     * 通过ID查询单条数据
     *
     * @param custId 主键
     * @return 实例对象
     */
    @Override
    public Customers queryById(String custId)
    {
        return this.customersDao.queryById(custId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Customers> queryAllByLimit(int offset, int limit)
    {
        return this.customersDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param customers 实例对象
     * @return 实例对象
     */
    @Override
    public Customers insert(Customers customers)
    {
        this.customersDao.insert(customers);
        return customers;
    }

    /**
     * 修改数据
     *
     * @param customers 实例对象
     * @return 实例对象
     */
    @Override
    public Customers update(Customers customers)
    {
        this.customersDao.update(customers);
        return this.queryById(customers.getCustId());
    }

    /**
     * 通过主键删除数据
     *
     * @param custId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String custId)
    {
        return this.customersDao.deleteById(custId) > 0;
    }
}